package com.browsesoft.htmlcomponent;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.w3c.dom.Element;

import com.browsesoft.ExtendElement;

public class NoRootTreeComponent extends HTMLMainPageTreeComponent {
	public NoRootTreeComponent(HTMLBasicComponent parent) throws Exception {
		super(parent);
	}

	public void init(HttpServletRequest request, Element e) throws Exception {
		// 创建子组件并保存组件元素
		super.init(request, e);
	}

	/**
	 * 处理用户请求，将需要Model处理的内容提交给Model
	 * 
	 * @param request
	 *            客户端请求
	 * @throws java.lang.Exception
	 */
	public void service(HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		super.service(request, response);
	}

	/**
	 * 根据Model的内容更新需要处理的元素内容，在产生页面时要调用
	 * 
	 * @throws java.lang.Exception
	 */
	protected void updateElement() throws Exception {
		// 删除element的description元素
		ExtendElement.removeNodes(element, "description");
		// 模板的根元素
		Object modelRootObject = ((HTMLTreeModel) model).getRootNode();
		if (modelRootObject != null) {
			createElement(element, modelRootObject, -1);
			Element des = (Element) element.getElementsByTagName("description")
					.item(0);
			des.removeChild(des.getFirstChild());
		}
	}
}